<?php
// +----------------------------------------------------------------------
// | QSCMS
// +----------------------------------------------------------------------
// | Copyright (c)  2025 https://www.qqss.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed QSCMS is not free software, commercial use must purchase official license from official website to avoid unnecessary legal disputes.
// +----------------------------------------------------------------------
// | Author: Contract 990504246@qq.com
// +----------------------------------------------------------------------

namespace app\userapi\event;

use think\facade\Db;

// 用户主动行为事件
class UserActive
{
    public function action($user, $event_name)
    {
        switch ($event_name) {
            // 用户登录成功，更新数据
            case 'user.login.success':
                $this->loginSuccess($user);
                break;
            // 用户每日登录
            case 'user.login.daily':
                $this->loginDaily($user);
                break;
            // 首次绑定邮箱
            case 'user.bind.email.first':
                $this->bindEmailFirst($user);
                break;
            // 用户每日签到
            case 'user.sign.daily':
                $this->signDaily($user);
                break;
            // 点赞别人的商品
            case 'user.goods.like':
                $this->goodsLike($user);
                break;
            // 回复别人的帖子
            case 'user.post.reply':
                $this->postReply($user);
                break;
            // 发布帖子
            case 'user.post.publish':
                $this->postPublish($user);
                break;
            // 关注别人
            case 'user.follow':
                $this->follow($user);
                break;
        }
    }

    public function loginSuccess($user)
    {
        Db::name('user')->where('id', $user['id'])->update([
            'lastlogintime' => date('Y-m-d H:i:s'),
            'ip'            => request()->ip(),
        ]);
    }

    public function loginDaily($user)
    {
        // 任务经验
    }

    public function bindEmailFirst($user)
    {
        // 任务经验
    }

    public function goodsLike($user)
    {
        // 任务经验
    }

    public function signDaily($user)
    {
        // 任务经验
    }

    public function postReply($user)
    {
        // 任务经验
    }

    public function postPublish($user)
    {
        // 任务经验.预留至v0.3.0版本
    }

    public function follow($user)
    {
        // 任务经验
    }


}